package cn.com.haopy.dataes.db.service.main.impl;

import cn.com.haopy.dataes.db.entity.main.HDApp;
import cn.com.haopy.dataes.db.mapper.main.HDAppMapper;
import cn.com.haopy.dataes.db.service.main.HDAppService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class HDAppServiceImpl extends ServiceImpl<HDAppMapper, HDApp> implements HDAppService {

    @Override
    public Page<HDApp> querySelective(String code, String name, Integer pageNo, Integer size, String sort, String order) {

        QueryWrapper<HDApp> queryWrapper = new QueryWrapper<>();

        if (StringUtils.hasText(code)) {
            queryWrapper.lambda().eq(HDApp::getCode, code);
        }

        if (StringUtils.hasText(name)) {
            queryWrapper.lambda().like(HDApp::getName, "%" + name + "%");
        }

        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }

        Page<HDApp> page = new Page<>(pageNo, size);

        return super.page(page, queryWrapper);
    }

    @Override
    public HDApp findByCode(String code) {
        QueryWrapper<HDApp> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(HDApp::getCode, code);

        return super.getOne(queryWrapper, false);
    }
}
